import numpy as np
import skimage
import matplotlib.pyplot as plt
import cv2
CNNS excel when used on unstructured data
from IPython.lib.display import YouTubeVideo
YouTubeVideo("_1MHGUC_BzQ")
Yellow - kernel (called weights or filters)
Green - image
Pink - output of convolution, called an activation or feature map
When CNNs are trained, these kernels are updated during backpropagation to find the optimal values of each of the filters.

# create a 2D matrix and a 3 by 3 kernel (2d matrix as well)
# write a function to do 2D convolutions using numpy
# run function on matrix and kernel with a stride of 1
# run function on matrix and kernel with a stride of 3
An image is technically 3D: (width, height, number of channels).
A typical image is RGB format, 3 channels representing red, green, and blue values of each pixel.
image_file = "https://i.kym-cdn.com/entries/icons/mobile/000/013/564/doge.jpg"
# load file using skimage into numpy array
# display image using plt
# print image shape
# print each channel of the image
# use a top sobel kernel and apply it to the image we loaded
Stride number of pixels the filter skips after each convolution. We have shown a stride of one so far.
Stride of 1:
Stride of 2:
Padding: adding pixels to the edges of the image, so the filter fits properly when being convolved across.
In practice, it seems the ReLU function performs the best for image tasks. There is much research on why this is the case, but for now keep it in mind when working with CNNs.
Intuitively, negative features are ones that the network should ignore, vs positive features are ones that the model should focus on.
Downsampling the input to reduce the size and enable the model to generalize feature extraction across varying orientations and scale of the image.
Intuitively: picking the best feature from each window when pooling.
# create a matrix and apply 2d max pooling to the matrix using numpy
Dropout: we have seen it before
Batch Normalization: normalizing activations (kernels) after a CNN layer.
# print the matrix we are working with again
# apply global average pooling to the sample matrix
# create the softmax and sigmoid functions, then apply them to an example 1d array of random values